def format_logs_to_html(logs):
    if not logs:
        return "<p>没有发现新的错误日志。</p>"
    html = """
    <html><head><style>table{width:100%;border-collapse:collapse;}th,td{border:1px solid #ddd;text-align:left;padding:8px;}th{background:#f2f2f2;}pre{white-space:pre-wrap;word-wrap:break-word;}</style></head><body><h2>错误日志报告</h2><table><tr><th>时间戳</th><th>消息</th><th>原始日志</th></tr>"""
    for log in logs:
        source = log.get('_source', {})
        timestamp = source.get('@timestamp', 'N/A')
        message = source.get('message', 'N/A')
        message_display = message[:300] + '...' if len(message) > 300 else message
        html += f"<tr><td>{timestamp}</td><td><pre>{message_display}</pre></td><td><pre>{source}</pre></td></tr>"
    html += "</table></body></html>"
    return html 